<template>
	<view class="index-content relative">
		<public-module></public-module>
		<view class="bg-white fixed z-index-100 left-0 top-0 w100 ">
			<view class="flex j-start a-center relative z-index-100 bg-white pt-2 px-3">
				<view style="min-width: 100rpx;" class="flex j-start a-center" @click="navigateTo('/pages/index/city')">
					<view class="mr-2" v-if="!cityInfo.cityName">城市</view>
					<view class="mr-2" v-if="cityInfo.cityName">{{cityInfo.cityName}}</view>
					<u-icon name="arrow-down" color="#888" size="18"></u-icon>
				</view>
				<view class="flex-1 ml-2">
					<u-search style="width: 100%;" placeholder="搜索项目" v-model="queryParams.name" :showAction="false"
						:clearabled="true" @blur="searchLists"></u-search>
				</view>
			</view>
			<filtrates-vue :show="showMask" @query="handleQuery" />
		</view>

		<view class="px-3 mt-3">
			<view class="flex j-start p-3 bg-white rounded-10 mb-2" v-for="(item,index) in listData" :key="item.id"
				@click="navigateTo('/pages/index/detail?id='+item.id)">
				<u--image :showLoading="true" :src="item.listImage" width="190rpx" height="180rpx" :radius="10">
					<view slot="error" style="font-size: 24rpx;">图片加载失败</view>
				</u--image>
				<view class="flex-1 ml-2">
					<view class="mb-1 font-bold font-32 ellipsis">{{item.name}}</view>
					<view class="flex j-start mb-1 tags">
						<text v-if="item.plate">{{item.plate}}</text>
						<text v-if="item.houseType">{{item.houseType}}</text>
						<text>{{item.floorSpace}}
							<block v-if="item.floorSpace&&!item.floorSpace.includes('㎡')">㎡</block>
						</text>
					</view>
					<view class="flex j-start mb-1 label" v-if="item.projectTag">
						<block v-for="(tag,intag) in item.projectTag" :key="intag">
							<text v-if="intag<3">{{tag}}</text>
						</block>
					</view>
					<view class="text-danger font-30">{{item.amountUnit}}</view>
				</view>
			</view>
			<empty v-if="listData.length==0" />

		</view>
	</view>
</template>
<script>
	import {
		houseList
	} from '@/api/house.js'
	import filtratesVue from './filtrates.vue'
	import {
		getLocation,
		reverseGeocoder
	} from '@/config/common.js'
	import {
		deWeight
	} from '@/utils/util.js'
	export default {
		components: {
			filtratesVue
		},
		data() {
			return {
				queryParams: {
					pageNo: 1,
					pageSize: 15,
					name: '',
					amountUnitFlag: '',
					areaCode: ''
				},
				listData: [],
				showMask: '-1'
			}
		},
		onPullDownRefresh() {
			if (uni.getStorageSync('token')) {
				this.getUserInfos()
			}
			this.isLoadMore = false;
			this.queryParams.pageNo = 1;
			this.listData = [];
			this.getList();
			setTimeout(function() {
				uni.stopPullDownRefresh();
			}, 500);
		},
		onReachBottom() {
			if (!this.isLoadMore) {
				this.isLoadMore = true;
				this.queryParams.pageNo += 1;
				this.getList();
			}
		},
		onLoad() {
			if (uni.getStorageSync('token')) {
				this.getUserInfos()
			}


		},
		onShow() {
			this.showMask = '-1';
			// #ifndef H5
			getLocation(res => {
				this.queryParams.areaCode = ''
				this.searchLists();
				// reverseGeocoder(res.longitude, res.latitude, geo => {
				// 	console.log(geo, '---')
				// 	this.$store.commit('setCityInfo', {
				// 		cityName: geo.ad_info.city,
				// 		province: geo.ad_info.province,
				// 		city: geo.ad_info.city,
				// 		area: geo.ad_info.district,
				// 	})
				// })
			})
			// #endif

			// #ifdef H5
			this.queryParams.areaCode = ''
			this.searchLists();
			// #endif


		},
		onHide() {

		},
		//分享
		onShareAppMessage() {
			wx.showShareMenu({
				withShareTicket: true,
				menus: ["shareAppMessage", "shareTimeline"],
			});
		},
		onShareTimeline() {
			return {
				path: "/pages/index/index",
			};
		},
		methods: {
			handleQuery(val) {
				this.queryParams.amountUnitFlag = val.amountUnitFlag;
				this.queryParams.areaCode = val.areaCode
				this.searchLists();
			},
			searchLists() {
				this.isLoadMore = false;
				this.queryParams.pageNo = 1;
				this.listData = [];
				this.getList();
			},
			getList() {
				houseList(this.queryParams).then(res => {
					if (res.data.list.length == 0) {
						let oldLoad = {}
						this.isLoadMore = true;
						oldLoad = Object.assign({}, this.queryParams);
						oldLoad.pageNo = this.queryParams.pageNo;
						this.queryParams = oldLoad
						this.$forceUpdate()
						return
					}

					this.isLoadMore = false;
					let oldList = this.listData || []
					oldList.push(...res.data.list)
					this.listData = oldList;
					this.listData = deWeight(this.listData)
				})
			}
		}
	}
</script>
<style lang="scss" scoped>
	.index-content {
		padding-top: 190rpx;
	}

	.buildimages {
		width: 190rpx;
		height: 180rpx;
	}

	.tags {
		text {
			display: inline-block;
			margin-right: 20rpx;
			padding-right: 20rpx;
			position: relative;
			font-size: 24rpx;

			&::after {
				content: '';
				position: absolute;
				top: 15%;
				bottom: 15%;
				right: 0;
				width: 1px;
				border-right: 1px solid #c6c6c6;
			}

			&:last-of-type::after {
				border: none;
			}
		}
	}

	.label {
		text {
			display: inline-block;
			padding: 4rpx 10rpx;
			background-color: #f4f4f4;
			font-size: 24rpx;
			margin-right: 20rpx;
			border-radius: 6px;
		}
	}
</style>